<?php
namespace app\front\controller\v2;
use app\front\controller\v2\BaseController;
use app\front\model\Userinfo as UserinfoModel;
use app\front\model\Store as StoreModel;
use app\front\model\Trade as TradeModel;
class ShowController extends BaseController
{
    public function testRedis(){
        logs("@@@@@@@@@@@@@@@.txt", "%%");
        $this->getShowService()->UpdateAwardForShopid();
    }
    
    public function test(){
        echo "11";
        $url='http://www.zfshlm.com/098f6bcd4621d373cade4e832627b4f6/zfshlm_5_0/public/index.php/front/v2.OutsideController/UpdateAwardForShopid';
        https_request($url);
    }
    
    public function showRule(){
        return view('v2/rule');
    }
    
    public function showStoreTOP(){
        return view('v2/banner4-link');
    }
    
    public function showStore(){
        //防止影响其他公众号 $list=$store->where('ISNULL(status)')->limit(2)->select();
        session('openid',null);
        $theme=TradeModel::where("status is NULL")-> select();  // -> order("id DESC")
        $this->assign('themelist',$theme);
        return view('v2/index');
    }
    
    public function showTodayOrder(){
        $res= $this->getOrderService()->showTodayOrder();
        $todayMoneySum=0;
        foreach( $res as $v )
        {
            $todayMoneySum= bcadd($todayMoneySum,$v['money'],2);
        }
        $this->assign('res', $res);
        $this->assign('todayMoneySum', $todayMoneySum);
        //带着参数跳转到gzhPay.html
        return view('v2/todayOrder');
    }
    
    
   public function showStoreForTrade(){
       //防止影响其他公众号
       session('openid',null);
       $trade_id= input('param.trade_id');
       $trade=TradeModel::where('id='.$trade_id)->find();
       $trade_name=$trade['trade_name'];
       $sign=$trade['sign_imgurl']; 
      // $list=Store::where('status is NULL and trade_id='.$trade_id)->select();
       $theme=TradeModel::where('status is NULL')->select();
       $this->assign('trade_name',$trade_name);
       $this->assign('sign',$sign);
       $this->assign('themelist',$theme);
       $this->assign('trade_id',$trade_id);
    //   $this->assign('list',$list);
       $this->assign('lock',1);
       return view('v2/index2');
   }
   
   public function zhifw(){
       $id=input('param.id');
       $date=StoreModel::where('id='.$id)->find();
       $this->assign('date', $date);
       return view('v2/zhifu');  
   }
   
   /**
   * 函数用途描述 :根据搜索框关键字动态显示店铺
   * @date: 2018年6月15日 下午7:31:22
   * @author: 孙洪亮
   * @param:  keyword
   * @return: 包含keyword的店铺列表
   */
   public function ajaxShowStore(){
       $this->getShowService()->ajaxShowStore();
   }
   
   /**
   * 函数用途描述 :要是店铺重名了，就用这方法给重名店铺加地理位置
   * @date: 2018年6月15日 下午7:39:12
   * @author: 孙洪亮
   * @param:  店铺名
   * @return: 加了地理位置的店铺信息
   */
   public function distanceStore($store_name){
       return  $this->getShowService()->distanceStore($store_name);
   }
   
 
   

   public function distance($dis){
     $this->getShowService()->distance($dis);
   }
   //  $store_data = Store::table('store')->where('status is NULL')->where('trade_id',$trade_id)->select();
   public function distanceTrade(){
     $this->getShowService()->distanceTrade();
   }
   

   public function QueryZhiFu(){
       $store_name = input('param.store_name');
       $storenum= count(StoreModel::where('store_name',$store_name)->where('status is NULL')->field('id')->select());
       if( $storenum==1){
           $store= StoreModel::where('store_name',$store_name)->where('status is NULL')->field('id')->find();
           $date=StoreModel::where('id='.$store['id'])->find();
           $this->assign('date', $date);
           return view('v2/zhifu');
       }else{
           $store=  $this->distanceStore($store_name);
           $store=json_decode(json_encode($store),true);
           $this->assign('store',$store);
           $this->assign('store_name',$store_name);
           return view('v2/selectStore');
       }
       
   }
   

   public function showSuccess(){
      $redpack= input('param.redpack');
      $CostMoney=input('param.CostMoney');
      $store_name=input('param.store_name');
     
      if($redpack==0){
         // $redpack="很遗憾，消费10元以上才有红包哦！";
          $redpack="很遗憾，红包是空的！！";
          $this->assign('store_name',  $store_name);
          $this->assign('redpack',  $redpack);
          return view('v2/hbjm');
       
      }else{
          if($redpack==($CostMoney/100)){
              $redpack=$store_name."\n恭喜您获得免单红包！  \n￥".$redpack;
              $this->assign('store_name',  $store_name);
              $this->assign('redpack',  $redpack);
              return view('v2/free');
          }else{
             // $redpack='来自'.$store_name."的￥".$redpack;
              $this->assign('store_name',  $store_name);
              $this->assign('redpack',  $redpack);
              return view('v2/no_free');
          }
      }
    
   
   }
   
   /**
   * 函数用途描述 :检查搜索框输入的店铺名是否存在
   * @date: 2018年6月15日 下午7:35:05
   * @author: 孙洪亮
   * @param:  店铺名
   * @return: null
   */
   public function checkStorename(){
       $store_name = input('param.store_name');
       $store_name='"'.$store_name.'"';
       $store= StoreModel::where('store_name='.$store_name)->where('status is NULL')->field('id')->find();
       $allow=false;
       if($store!=null){
           $allow="true";
       }else{
           $allow=$store_name;
       }
       echo json_encode($allow);
   }
   

   /**
   * 函数用途描述 :要不是不知道这方法是谁调的 我早给它删了，艹！
   * @date: 2018年6月15日 下午7:36:27
   * @author: 孙洪亮
   * @param:  null
   * @return: null
   */
  public  function existUserinfo($openid){
      $Userinfo = UserinfoModel::where('openid',$openid)->field('id,openid,nickname,money,headimgurl')->find();
      $Userinfo = json_decode($Userinfo,true);
      return  $Userinfo;
  }
  

}
